package mycharstream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test01 {
    public static void main(String[] args) throws IOException {
        //创建拷贝的对象
        File file1 = new File("D:\\mingw64");

        //创建被拷贝的对象
        File file2 = new File("D:\\File\\copy");

        copy(file1,file2);
    }
    public static void copy(File src,File dest) throws IOException {
        dest.mkdirs();
        File[] files = src.listFiles();
        for (File file : files) {
            if(file.isFile()){
                FileInputStream fis = new FileInputStream(file);
                FileOutputStream fos = new FileOutputStream(new File(dest,file.getName()));
                byte[]bytes = new byte[1024 * 1024 * 20];
                int len;
                while ((len = fis.read(bytes) ) != -1){
                    fos.write(bytes,0,len);
                }
                fos.close();
                fis.close();
            }else {
                copy(file,new File(dest,file.getName()));
            }
        }
    }
}
